<?php
	class Option extends Model{
		private $_OptionId;
		private $_Description;
		private $_Active;

		public function __construct($arrInitialValues = null){
			parent::__construct();
			
			if(isset($arrInitialValues['option_id']))
				$this->setOptionId($arrInitialValues['option_id']);
			else
				$this->setOptionId(0);

			if (isset($arrInitialValues['description']))
				$this->setDescription($arrInitialValues['description']);
			else
				$this->setDescription('');

			if (isset($arrInitialValues['active']))
				$this->setActive($arrInitialValues['active']);
			else
				$this->setActive(0);
		}
		
		public function setOptionId($value){
			$this->_OptionId = $value;
		}
		
		public function getOptionId(){
			return $this->_OptionId;
		}
		
		public function setDescription($value){
			$this->_Description = $value;
		} 
		
		public function getDescription(){
			return $this->_Description;
		} 
		
		public function setActive($value){
			$this->_Active = $value;
		}
		
		public function getActive(){
			return $this->_Active;
		}
		
		public function getAll($surveyId){
			$query = '
				SELECT * 
				FROM options
				WHERE survey_id = ' . $surveyId;
			
			$dbHelper = new DBHelper($query);
			return $dbHelper->getResult();
		}
		
		public function getOption($optionId){
			$query = '
				SELECT *
				FROM options
				WHERE option_id = ' . $optionId;
			
			$dbHelper = new DBHelper($query);
			return $dbHelper->getResult();
		}
		
		public function delete(){
			$query = '
				DELETE 
				FROM options
				WHERE option_id = ' . $this->_OptionId;

			$dbHelper = new DBHelper($query);
			return $dbHelper->getNumRows();
		}
		
		public function create($surveyId, $option){
			$query = '
				INSERT INTO options
				(description, survey_id,active)
				VALUES
				("' . $option . '",' . $surveyId . ',1)';
			 
			$dbHelper = new DBHelper($query);
			return $dbHelper->getNumRows();
		}
		
		public function update($surveyId){
			$query = '
				UPDATE options
				SET description = "' . $this->getDescription() . '", 
				survey_id = "' . $surveyId . '", 
				active = ' . $this->getActive() . ' 
				WHERE option_id = ' . $this->getOptionId();
				
			$dbHelper = new DBHelper($query);
			return $dbHelper->getNumRows();
		}
		
	}

?>